package com.wlx.jdbc.dao.impl;

import com.wlx.day01.entity.Users;
import com.wlx.javaSE.utils.DBPoolUtils;
import com.wlx.jdbc.dao.UserDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public boolean updateUser(Users users) {
        Connection conn= DBPoolUtils.getConnection();
        if (conn!=null)
        {
            try {
                String sql="update users set userid=?,username=?,userpwd=?,userage=?,usersex=? where userid=?";
                PreparedStatement pstmt=conn.prepareStatement(sql);
                pstmt.setInt(1,users.getUserid());
                pstmt.setString(2,users.getUsername());
                pstmt.setString(3,users.getUserpwd());
                pstmt.setInt(4,users.getUserage());
                pstmt.setString(5,users.getUsersex());
                pstmt.setInt(6,users.getUserid());
                int num=pstmt.executeUpdate();
                if (num>0)
                {
                    return true;
                }
                else {
                    return false;
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
}
